//
//  YHPublicVC.swift
//  XLWB
//
//  Created by key on 16/6/25.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class YHPublicVC: UIViewController {

    var islogin : Bool = YHUserAccountTool.sharedUserAccountTool.islogin
    
    //初始化View
    var VisitorView : YHVisitorView?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //设置导航条
        setNav()
        
        
        
        
    }
    
    //MARK: - 加载视图
    override func loadView() {
        
        //判断
        if !islogin {
            
            VisitorView = YHVisitorView()
            
            //实现闭包
            VisitorView?.visitorBag = {
                
                //跳转控制器
                self.presentViewController(UINavigationController(rootViewController: YHOauthVC()), animated: true, completion: nil)
                
                
            }
            
            self.view = VisitorView
            
        }else {
            
            super.loadView()
            
        }
        
    }

    
    //MARK: - 设置导航条
    @objc private func setNav() {
        
        if islogin {
            
            return
            
        }else{
        
            navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
            
            navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
            
        }
    }
    
    //点击注册 登陆
    @objc private func loginClick() {
        
        //跳转控制器
        presentViewController(UINavigationController(rootViewController: YHOauthVC()), animated: true, completion: nil)
        
    }

}
